<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2020-12-02
  Time: 16:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <base href="<%=request.getContextPath()%>/"/>
  <link rel="stylesheet" href="webjars/layui/2.5.6/css/layui.css">
</head>
<body>
        <div class="layui-main">
            <script type="text/html" id="toolbar">
                <div class="layui-form-item">
                    <form class="layui-form" id="tou">
                        <label class="layui-form-label" style="width: 100px">申领单号:</label>
                        <input type="text" name="applyMasterNo" id="applyMasterNo" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left">

                        <label class="layui-form-label" style="width: 100px">申领方式:</label>
                        <%--<div class="layui-input-block" style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px;margin-left: 10px">
                            <select name="addStid" lay-filter="staff" lay-verify="required" id="staff" >
                                <option value="">请选择</option>
                                <option value="0">手动申领</option>
                                <option value="1">自动申领</option>
                            </select>
                        </div>--%>
                        <button type="button" class="layui-btn" onclick="search()"  style="float: left;margin-left: 20px">查询</button>
                    </form>

                    <%--<button type="button" class="layui-btn" onclick="add()" style="float: left;margin-left: 20px">添加申领</button>--%>
                </div>

            </script>
            <table id="roleTb" lay-filter="roleTb"></table>
            <script type="text/html" id="action">
                {{#  if(d.applyMasterStatuses== "0"){ }}
                <a class="layui-btn layui-btn-xs" lay-event="update">处理</a>
                <%--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>--%>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="xq">详情</a>
                {{#  } }}
                {{#  if(d.applyMasterStatuses== "1"){ }}
                <a class="layui-btn layui-btn-xs">已处理</a>
                <%--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>--%>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="xq">详情</a>
                <%--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="xq" onclick="add()">详情</a>--%>
                {{#  } }}
            </script>
        </div>




        <div style="display: none" id="xq">
            <form class="layui-form"  action="" lay-filter="xq">
                <div class="layui-form-item" style="margin-top: 30px">
                    <table id="roleTb1" lay-filter="roleTb1"></table>
                </div>

            </form>
        </div>



        <div style="display: none" id="add">
            <form class="layui-form"  action="" lay-filter="add">
                <div class="layui-form-item" style="margin-top: 30px">
                    <input name="applyMasterId" type="hidden"/>
                    <input name="applyMasterSubNo" value="52122120" type="hidden"/><%--子单号--%>
                    <input name="applyMasterMethod" value="0" type="hidden"/><%--申领方式--%>
                    <input name="applyMasterStatuses" value="0" type="hidden"/><%--处理状态--%>
                    <input name="applyName" value="张三" type="hidden"/><%--申领人--%>
                    <input name="createBy" value="张三" type="hidden"/><%--创建者--%>
                    <input name="applyChildStatus" value="0" type="hidden"/><%--物资处理状态--%>
                    <input name="applyChildId" type="hidden"/><%--物资子表id--%>
                    <label class="layui-form-label" style="margin-bottom: 20px">物资名称:</label>
                    <input type="text" name="cgCode" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                    <label class="layui-form-label" style="margin-bottom: 20px">申领数量:</label>
                    <input type="text" name="applyChildNum" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                    <label class="layui-form-label" style="margin-bottom: 20px">经费来源:</label>
                    <%--<input type="text" name="applySource" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">--%>
                    <div class="layui-input-inline" style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                        <select name="applySource" lay-verify="required">
                            <option value="">请选择</option>
                            <option value="0">科室白支票</option>
                            <option value="1">科研经费</option>
                        </select>
                    </div>
                    <%--<label class="layui-form-label" style="margin-bottom: 20px">使用标志:</label>--%>
                    <label class="layui-form-label" style="margin-bottom: 20px">申领单位:</label>
                    <%--<input type="text" name="departmentCode" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">--%>
                    <div class="layui-input-inline" style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                        <select name="departmentCode" lay-verify="required">
                            <option value="">请选择</option>
                            <option value="儿科">儿科</option>
                            <option value="外科">外科</option>
                            <option value="口腔科">口腔科</option>
                            <option value="皮肤科">皮肤科</option>
                        </select>
                    </div>


                </div>

            </form>
            <table id="roleTb2" lay-filter="roleTb2"></table>
        </div>


            <div id="tree"></div>

<script src="webjars/layui/2.5.6/layui.js"></script>
<script>

    function cx(){

    }
        //表格初始化
        layui.use(["table"],function () {
            let table=layui.table;
            table.render({
                id:"roleTb",
                elem:"#roleTb",
                url:"sl1/search",
                toolbar: "#toolbar",
                page:true,
                cols:[[
                    //{title:"id",field:"departmentId"},
                    {title:"申领单号",field:"applyMasterNo"},
                    {title:"申领单位",field:"departmentCode"},
                    //{title:"物资名称",field:"cgName"},
                    {title:"申领方式",
                        templet:function (data){
                            if (data.applyMasterMethod==0){
                                return "<span>手动申领</span>"
                            }else {
                                return "<span>自动申领</span>"
                            }},
                        field:"applyMasterMethod"},
                    {title:"处理状态",
                        templet:function (data){
                            if (data.applyMasterStatuses==0){
                                return "<span>未处理</span>"
                            }else {
                                return "<span>已处理</span>"
                            }},
                        field:"applyMasterStatuses"},
                    {title:"申领人",field:"applyName"},
                    {title: "操作",toolbar:"#action"}
                ]]
            })
            table.on("tool(roleTb)",function ({data,event}){
                switch (event) {
                    case "update":
                        update(data.applyMasterId);
                        break;
                    case "del":
                        del(data.applyMasterId);
                        break;
                    case "xq":
                        xq(data.applyMasterNo);
                }
            });

        })




    function xq(applyMasterNo){
        layui.use(["layer","jquery","form","table"],function(){
            console.log(applyMasterNo)

            let $ = layui.$;
            let form = layui.form;
            let layer = layui.layer;
            let table = layui.table;
            //$("#add>form")[0].reset();
            //$.post("slz/search",{applyMasterNo:applyMasterNo})
            table.render({
                id:"roleTb1",
                elem:"#roleTb1",
                url:"slz/search?applyMasterNo="+applyMasterNo,
                //toolbar: "#toolbar",
                //page: true,
                cols:[[
                    {title:"物资编码",field:"cgCode"},
                    {title:"申领数量",field:"applyChildNum"},
                    {title:"处理状态",
                        templet:function (data){
                            if (data.applyChildStatus==0){
                                return "<span>未处理</span>"
                            }else {
                                return "<span>物资出库</span>"
                            }},
                        field:"applyChildStatus"},
                    {title:"经费来源",
                        templet:function (data){
                            if (data.applySource==0){
                                return "<span>科室白支票</span>"
                            }else {
                                return "<span>科研经费</span>"
                            }},
                        field:"applySource"},
                ]]
            })
            layer.open({
                type:1,
                offset:'50px',
                skin:'layui-layer-molv',
                area:["700px","450px"],
                content:$("#xq"),
                btn:["确定","取消"],

            });
        });
    }



    function add(){
        layui.use(["layer","jquery","form","table"],function(){
            let $ = layui.$;
            let form = layui.form;
            let layer = layui.layer;
            let table = layui.table;
            $("#add>form")[0].reset();
            table.render({
                id:"roleTb",
                elem:"#roleTb2",
                url:"wz/search",
                //toolbar: "#toolbar",
                page: true,
                cols:[[
                    {title:"物资编码",field:"cgCode"},
                    {title:"物资名称",field:"cgName"},
                    {title:"助记码",field:"inputCode"},
                    {title:"物资单位",field:"packUnit"},
                ]]
            })
            layer.open({
                type:1,
                offset:'50px',
                skin:'layui-layer-molv',
                area:["700px","510px"],
                content:$("#add"),
                btn:["确定","取消"],
                yes(){
                    let params=form.val("add");
                    console.log(params);
                    $.post("sl/add",params)
                        .done(({msg})=>{
                            table.reload("roleTb");
                            layer.close(layer.index);
                            layer.msg(msg);
                        });
                }
            });
        });
    } //添加



    function del(applyMasterId){
        layui.use("jquery",function(){
            //alert(applyMasterId);
            let layer=layui.layer;
            layui.$.post('/sl/del/',{applyMasterId:applyMasterId})
                .done(({msg})=>{
                    layui.table.reload("roleTb");
                    layer.msg(msg);
                });
        });
    }






        //修改
        function update(applyMasterId) {
            //console.log(data);
            layui.use(["layer","jquery","form"],function () {
                let layer=layui.layer;
                let $=layui.$;
                layui.form.val("update",applyMasterId);
                        let params=layui.form.val("update");
                        $.post("sl1/update",{applyMasterId:applyMasterId})
                        .done(({msg})=>{
                            layer.close(layer.index);
                            layer.msg(msg);
                            layui.table.reload("roleTb");
                        });
            })
        }









    function search() {
        layui.use('table', function() {
            let table = layui.table;
            table.reload('roleTb', {where: {applyMasterNo: document.getElementById('applyMasterNo').value}});
        })
    }




</script>
</body>
</html>
